package com.xinhe.cn.cpbox.mapper;

import com.xinhe.cn.cpbox.entity.po.UserOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 消费订单 Mapper 接口
 * </p>
 *
 * @author LHB
 * @since 2021-10-09
 */
@Repository
public interface UserOrderMapper extends BaseMapper<UserOrder> {
    @Select("select * from user_order where order_id=#{orderId}")
    UserOrder findByOrderId(@Param("orderId") String orderId);

    @Transactional
    @Delete(value = "delete from user_order where create_time<=#{time} and is_pay=0")
    int deleteNoPayOrder(@org.springframework.data.repository.query.Param("time") String time);

    @Select("select * from user_order uo left join user_info ui on uo.open_id=ui.open_id where uo.is_pay=1 " +
            "and uo.create_time< #{endTime} and uo.create_time >= #{startTime} " +
            "and ui.extend_id is not null and ui.extend_id<>''")
    List<UserOrder> getPayOrderByTime(String startTime, String endTime);
}
